
import glob
import paho.mqtt.client as mqtt
import uuid


import logging

logging.basicConfig(level = logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

logger = logging.getLogger(__name__)


def send_mqtt_message(broker_address="47.110.239.14", broker_port=1883, topic="test/topic", message="test_message"):
    # 连接 MQTT 代理
    client = mqtt.Client()
    # client.connect("mqtt_broker_address", 1883)  # 替换为您的 MQTT 代理地址和端口

    # 建立连接
    client.connect(broker_address, broker_port)

    # 发布数据到指定主题
    client.publish(topic, message)

    # 断开 MQTT 连接
    client.disconnect()

def get_mac_address():
    "获取系统的MacAddress"

    if glob.glob("/root/.mac"):
        
        with open('/root/.mac') as f:

            mac = f.read().strip()
    else:    
        node = uuid.getnode()

        mac = uuid.UUID(int=node).hex[-12:]

    return mac



if __name__ == "__main__":

    print(get_mac_address())

